package com.beamfield.controller.manage.sys;

import com.alibaba.fastjson.JSON;
import com.beamfield.common.ApiResult;
import com.beamfield.common.PageResult;
import com.beamfield.controller.common.BaseController;
import com.beamfield.model.Manufactor;
import com.beamfield.service.manage.sys.ManufactorService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import javax.servlet.http.HttpServletRequest;

/**
 * @author Zephyr
 * @description:
 * @date 2019/10/29
 */
@RequestMapping("/cms/material/manufactor")
@Controller
public class ManufactorController extends BaseController {

    @Autowired
    private ManufactorService manufactorService;

    @RequestMapping("/manufactor_list")
    public ModelAndView manufactorList(){
        return new ModelAndView();
    }


    @RequestMapping("/doSave")
    @ResponseBody
    public ApiResult save(String manufactorJson){
        Manufactor manufactor = JSON.parseObject(manufactorJson, Manufactor.class);
        return manufactorService.save(manufactor);
    }

    @RequestMapping("/doUpdate")
    @ResponseBody
    public ApiResult update(String manufactorJson){
        Manufactor manufactor = JSON.parseObject(manufactorJson, Manufactor.class);
        return manufactorService.update(manufactor);
    }

    @RequestMapping("/doDelete")
    @ResponseBody
    public ApiResult delete(Long id){
        return manufactorService.delete(id);
    }

    @RequestMapping("/list")
    @ResponseBody
    public PageResult list(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        String offset = request.getParameter("offset");
        String limit = request.getParameter("limit");
        String name = request.getParameter("name");
        return manufactorService.list(name, beamId, offset, limit);
    }

    @RequestMapping("/getAll")
    @ResponseBody
    public ApiResult getAll(HttpServletRequest request){
        Long beamId = super.getBeamId(request);
        return manufactorService.getAll(beamId);
    }
}
